package com.xuecheng.teaching.controller;

import com.xuecheng.api.teaching.CompanyApi;
import com.xuecheng.api.teaching.model.dto.CompanyDTO;
import com.xuecheng.api.teaching.model.dto.WorkRecordDTO;
import com.xuecheng.common.domain.uaa.LoginUser;
import com.xuecheng.teaching.common.util.UAASecurityUtil;
import com.xuecheng.teaching.service.CompanyService;
import com.xuecheng.teaching.service.WorkRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.mapping.ResultFlag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教育机构 前端控制器
 */
@Slf4j
@RestController
public class CompanyController implements CompanyApi {

    @Autowired
    private CompanyService companyService;

    @Autowired
    private WorkRecordService workRecordService;

    @GetMapping("l/company/{tenantId}")
    public CompanyDTO getByTenantId(@PathVariable("tenantId") Long tenantId) {
        return companyService.getByTenantId(tenantId);
    }

    @PostMapping("work-record")
    public WorkRecordDTO createWorkRecord(@RequestBody WorkRecordDTO workRecordDTO) {
        String username = UAASecurityUtil.getUser().getUsername();

        return workRecordService.createWorkRecord(workRecordDTO, username);
    }

    //查询 公司 资料 回显
    @GetMapping("my-company")
    public CompanyDTO companyDetail() {
        LoginUser user = UAASecurityUtil.getUser();
        System.out.println(user);
        CompanyDTO company = UAASecurityUtil.getCompany();

        CompanyDTO dto = companyService.getCompanyDetail(company);
        return dto;
    }

    @PutMapping("company")
    public Boolean modifyCompany(@RequestBody CompanyDTO companyDTO){

        Boolean resultFlag = companyService.modifyCompany(companyDTO);

        return resultFlag;
    }


}
